<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" media="all" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui/echarts.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.6.1.js"></script>
    <style>
        .layui-form-item {
            padding-right: 50px;
        }
    </style>
</head>
<body style="background-image: url('http://localhost:8080/FirstPhase_war/picture/14.png')">
<div id="container" style="
            width: 400px;
            height: auto;
            background-color: #ffffff;
            margin: 10% auto;
            border-radius: 15px;
            padding:50px 50px 10px 30px">
    <h1 style="text-align: center;
            margin: 15px 0;
            letter-spacing: 1px;
            color: #273c75;">欢迎来到心理测试系统</h1>
    <form class="layui-form" lay-filter="form1">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" class="layui-input" required placeholder="请输入账号"><br>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" class="layui-input" required placeholder="请输入密码"><br>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">记住密码</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="checked" name="test" lay-skin="switch">
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
        <div class="sing-up">
            <span>没有账户？</span><br>
            <a>注册</a>
        </div>
    </form>
</div>
</body>
</html>


<script>
    const form = layui.form; //layui中checkbox会自动隐藏

    form.on('submit(formDemo)', function () {
        let val = form.val("form1");

        $.ajax({
            url: '${pageContext.request.contextPath}/users/login',
            method: 'post',
            data:val,
            success:function (res){
                if(res.code == 0){
                    window.location.href='${pageContext.request.contextPath}/subject.jsp'
                }else {
                    layer.msg(res.msg,{icon:5})
                }
            }
        })
    });
</script>